package com.yc.cinema.mapper;

import com.yc.cinema.entity.Movie;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface MovieMapper {

    @Results(
            id = "rm2",
            value = {
                    @Result(id = true,column = "id",property = "id"),
                    @Result(column = "begin_time",property = "beginTime"),
                    @Result(column = "end_time",property = "endTime"),
                    @Result(column = "id",property = "plans",
                    many = @Many(
                            select = "com.yc.cinema.PlanMapper.selectByMid",
                            fetchType = FetchType.LAZY
                    ))
            }
    )
    @Select("select *from movie where id = #{id}")
    Movie selectById(int id);

    // @ResultMap ==> resultMap = 'rm2'
    @ResultMap("rm2")
    @Select("select *from movie where name like concat('%',#{name},'%')")
    List<Movie> selectLikeName(String name);
}
